package com.osfw.dbadminer.entity.operlog;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.osfw.framework.core.entity.BasicEntity;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.Date;

/**
 * 数据库SQL执行日志记录
 */
@Data
@Accessors(chain = true)
public class DbaOperLog extends BasicEntity {
    private static final long serialVersionUID = 1L;

    /* 日志主键 */
    @TableId(value = "oper_id_", type = IdType.ASSIGN_ID)
    private Long operId;

    /* 数据库连接ID */
    @TableField(value = "connect_id_")
    private Long connectId;

    /* 数据库连接名称 */
    @TableField(value = "connect_name_")
    private String connectName;

    /* 数据库名称 */
    @TableField(value = "database_name_")
    private String databaseName;

    /* 数据表名称 */
    @TableField(value = "datatable_name_")
    private String datatableName;

    /* 操作类型 */
    @TableField(value = "oper_type_")
    private String operType;

    /* 操作人员ID */
    @TableField(value = "oper_user_id_")
    private Long operUserId;

    /* 操作人员姓名 */
    @TableField(value = "oper_user_name_")
    private String operUserName;

    /* 操作人员部门ID */
    @TableField(value = "oper_dept_id_")
    private Long operDeptId;

    /* 操作人员部门名称 */
    @TableField(value = "oper_dept_name_")
    private String operDeptName;

    /* 操作地址 */
    @TableField(value = "oper_ip_")
    private String operIp;

    /* 操作地点 */
    @TableField(value = "oper_location_")
    private String operLocation;

    /* 操作时间 */
    @TableField(value = "oper_time_")
    private Date operTime;

    /* 是否审批 */
    @TableField(value = "is_approval_")
    private Integer isApproval;

    /* 审批流程实例ID */
    @TableField(value = "act_procinst_id_")
    private Long actProcinstId;

    /* 执行SQL */
    @TableField(value = "exec_stmt_")
    private String execStmt;

    /* 执行状态（0-正常，1-异常） */
    @TableField(value = "exec_status_")
    private Integer execStatus;

    /* 执行结果 */
    @TableField(value = "exec_result_")
    private String execResult;

    /* 执行时间 */
    @TableField(value = "exec_time_")
    private Date execTime;

    /* 消耗时间 */
    @TableField(value = "cost_time_")
    private Double costTime;


    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                .append("operId", getOperId())
                .append("connectId", getConnectId())
                .append("databaseName", getDatabaseName())
                .append("datatableName", getDatatableName())
                .append("operType", getOperType())
                .append("operUserId", getOperUserId())
                .append("operUserName", getOperUserName())
                .append("operDeptId", getOperDeptId())
                .append("operDeptName", getOperDeptName())
                .append("operIp", getOperIp())
                .append("operLocation", getOperLocation())
                .append("operTime", getOperTime())
                .append("isApproval", getIsApproval())
                .append("actProcinstId", getActProcinstId())
                .append("execStmt", getExecStmt())
                .append("execResult", getOperTime())
                .append("execStatus", getCostTime())
                .append("execErrorMsg", getCostTime())
                .append("execTime", getCostTime())
                .append("costTime", getCostTime())
                .toString();
    }
}
